$(function () {//初始化
    $("li.flexLi").click(function () {
        $("li.flexLi").removeClass("actives");
        $(this).addClass("actives");
    });
    $("ul.ulFlex>li").eq(0).click();
});

var avatarUp = "";

function iconTypeChange() {
    avatarUp = new $IconUpload("avatar");
    avatarUp.setIconUploadBarId("progressBar");
    avatarUp.initIcon();
}

function uploadAdd(types) {//点击加载影像
    var reservationsId = document.getElementById("reservationsId").value;
    var customerId = document.getElementById("customerId").value;
    var iconType = types.innerHTML;
    var cri = customerId + "," + reservationsId + "," + iconType;
    $.ajax({
        type: "POST",
        url: Feng.ctxPath + "/doctorLooked/getIconInfo/" + cri,
        data: {},
        dataType: "json",
        success: function (data) {
            $("#contentBoxs").html("");
            var obj = {};
            for (var i = 0; i < data.length; i++) {
                if (obj.hasOwnProperty(data[i].iconName)) {
                    obj[data[i].iconName].push(data[i]);
                } else {
                    obj[data[i].iconName] = [];
                    obj[data[i].iconName].push(data[i]);
                }
            }
            for (var item in obj) {
                var timecontainer = $("<div id='" + obj[item][0].diagnoseTime + "' style='box-shadow: 0 0 5px #aaaaaa;margin-top: 20px;padding: 0 0 20px;border-radius: 5px;margin-bottom: 10px;'>" +
                    "<p style='background: #337ab7;color: white;text-indent: 1em;line-height: 40px;'><span>" + obj[item][0].iconName + "</span></p></div>");
                $("#contentBoxs").append(timecontainer);
                for (var w = 0; w < obj[item].length; w++) {
                    var img = $(" " +
                        "<span style='display:inline-block;width: 300px;border: 1px solid #cccccc;margin-left: 20px;position: relative;text-align: center;margin-bottom: 5px;'>" +
                        "<a style='width: 150px;margin:0 auto;' href='javascript:;' class='thumbnail'>" +
                        "<img style='margin: 0;width: 100%;' class='layui-upload-img imagePath' src='" + obj[item][w].imageUrl + "' alt=''></a>" +
                        "<span>" + (obj[item][w].diagnoseTime).substring(0, 10) + "</span>" +
                        "<div>" + (obj[item][w].addName) + "上传于" + (obj[item][w].addTime).substring(0, 10) + "</div>" +
                        "<button onclick='imgDel(" + obj[item][w].id + ")' class='btn btn-xs btn-default' type='button' style='z-index: 9;position: absolute;bottom: 5px;right: 15px;background:white;color: #333333;'>" +
                        "<span class='glyphicon glyphicon-trash spanmis' ></span></button></span>");
                    timecontainer.append(img);
                }
            }
        }
    });
}

function imgDel(id) {//删除影像图片
    if (confirm("确定删除图片?")) {
        $.ajax({
            url: Feng.ctxPath + "/doctorLooked/imgDel",
            type: "post",
            data: {
                id: id
            },
            success: function (data) {
                Feng.success('操作成功!');
                location.reload();
            },
            error: function (data) {
                alert('没有权限，请联系管理员!');
            }
        });
    }
}

function openIconType() {//打开上传影像
    var reservationsId = document.getElementById("reservationsId").value;
    var customerId = document.getElementById("customerId").value;
    var cri = reservationsId + "," + customerId;
    var index = layer.open({
        type: 2,
        title: '请关联预约',
        area: ['50%', '50%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/openIconType/' + cri
    });
    this.layerIndex = index;
}

function uploadicon() {//上传影像
    var iconType = document.getElementById("iconType").value;
    var remarks = document.getElementById("remarks").value;
    if (iconType == '请选择' || remarks == '') {
        alert("请选择上传图片类型!");
    } else {
        avatarUp.initIcon();
    }
}